<template>
    <el-form :model="cEquipmentForm" status-icon :rules="rules" ref="cEquipmentForm"
             label-width="150px"
             style="margin-top: 10px;color: #1f2d3d">
        <el-form-item class="form-label" label="设备编码" prop="eid">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.eid" placeholder="设备编码"
                          maxlength="11" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="所属建筑名称" prop="objectName">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.objectName" placeholder="所属建筑名称"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="地理位置" prop="location">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.location" placeholder="地理位置"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="经度" prop="lon">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.lon" placeholder="经度"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="纬度" prop="lat">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.lat" placeholder="纬度"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="设备类别" prop="deviceType">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.deviceType" placeholder="设备类别"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="设备名称" prop="deviceName">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.deviceName" placeholder="设备名称"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="型号" prop="model">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.model" placeholder="型号"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="所在层数" prop="infloor">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.infloor" placeholder="所在层数"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="设备固定形式" prop="fixedForm">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.fixedForm" placeholder="设备固定形式"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="底部螺栓直径" prop="boltDiameter">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.boltDiameter" placeholder="底部螺栓直径(mm)"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="重新购置造价" prop="purchaseCost">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.purchaseCost" placeholder="重新购置造价"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="厂家" prop="manufacturers">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.manufacturers" placeholder="厂家"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="长" prop="size">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.size" placeholder="长"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="宽" prop="width">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.width" placeholder="宽"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="高" prop="height">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.height" placeholder="高"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="空机柜和两个子架质量之和" prop="weight">
            <el-col :span="19">
                <el-input v-model="cEquipmentForm.weight" placeholder="空机柜和两个子架质量之和(kg)"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="关联子任务" prop="sid" style="display: none">
            <el-input v-model="cEquipmentForm.sid"
                      maxlength="20" autocomplete="off"/>
        </el-form-item>
    </el-form>
</template>

<script>
    import qs from 'qs';

    export default {
        name: "NewCorrespondEquipment",
        data() {
            return {
                cEquipmentForm: {
                    id: '',
                    eid: '',
                    objectName: '',
                    location: '',
                    lon: '',
                    lat: '',
                    deviceType: '',
                    deviceName: '',
                    model: '',
                    infloor: '',
                    fixedForm: '',
                    boltDiameter: '',
                    purchaseCost: '',
                    manufacturers: '',
                    size: '',
                    width: '',
                    height: '',
                    weight: '',
                    sid: ''
                },
                rules: {
                    eid: [],
                    objectName: [],
                    location: [],
                    lon: [],
                    lat: [],
                    deviceType: [],
                    deviceName: [],
                    model: [],
                    infloor: [],
                    fixedForm: [],
                    boltDiameter: [],
                    purchaseCost: [],
                    manufacturers: [],
                    size: [],
                    width: [],
                    height: [],
                    weight: []
                }
            }
        },
        mounted() {
            if (this.id !== -1) {
                axios.post("/bjdzms/correspondIndoorEquipment/findById",
                    qs.stringify({
                        'id': this.id
                    })).then(res => {
                    this.cEquipmentForm = res.data.datas;
                });
            }
        },
        props: {
            sid: {
                type: Number,
                default: -1
            },
            id: {
                type: Number,
                default: -1
            }
        },
        methods: {
            to(path) {
                this.$router.push({name: path});
            },
            submitForm() {
                if (this.id !== -1) {
                    this.cEquipmentForm.id = this.id;
                    axios.post("/bjdzms/correspondIndoorEquipment/upd",
                        qs.stringify(this.cEquipmentForm)
                    ).then(res => {
                        this.$emit('updateData');
                    });
                } else {
                    this.cEquipmentForm.sid = this.sid;
                    axios.post("/bjdzms/correspondIndoorEquipment/add",
                        qs.stringify(this.cEquipmentForm)
                    ).then(res => {
                        this.$emit('updateData');
                    });
                }
            }
        }
    }
</script>

<style>
    .el-upload-dragger {
        height: 40px !important;
    }
</style>

<style scoped>
    .el-header {
        background: #EBEBEB;
        color: #e5e9ef;
        font-size: 2em;
        line-height: 80px;
        border: 5px solid #EBEBEB;
    }

    .el-main {
        background: #fff;
    }

    .el-container {
        height: 100%;
    }

    .el-form-item {
        width: 610px;
    }
</style>
